package com.cmccgz.udacs_landlord_webapp.bean;


import com.cmccgz.baselibrary.utils.StringUtils;
import com.cmccgz.udacs_landlord_webapp.base.AppConfig;

import java.io.Serializable;

public class UserInfo implements Serializable {
    private String head_id;//头像url
    private String nick_name;//昵称
    private String sex;//性别
    private String age;//年龄
    private String type;//角色类型
    private String userId;//角色类型

    public UserInfo(String head_id, String nick_name, String sex, String age, String type, String userId) {
        this.head_id = head_id;
        this.nick_name = nick_name;
        this.sex = sex;
        this.age = age;
        this.type = type;
        this.userId = userId;
    }

    public UserInfo(String head_id, String nick_name, String sex, String age, String type) {
        this.head_id = head_id;
        this.nick_name = nick_name;
        this.sex = sex;
        this.age = age;
        this.type = type;
    }

    public String getHead_id() {
        return head_id;
    }

    public void setHead_id(String head_id) {
        this.head_id = head_id;
    }

    public String getNick_name() {
        return nick_name;
    }

    public void setNick_name(String nick_name) {
        this.nick_name = nick_name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getAge() {
        return age;
    }

    public void setAge(String age) {
        this.age = age;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public UserInfo copyNewInstance() {
        return new UserInfo(head_id, nick_name, sex, age, type, userId);
    }

    public static String getImagePath(String mediaId) {
        if (StringUtils.isEmpty(mediaId)) {
            return "";
        }
        return AppConfig.getBaseUrl()
                + "download?" + "mediaId=" + mediaId + "&type=1";
    }

    public String getImagePath() {
        if (StringUtils.isEmpty(head_id)) {
            return "";
        }
        return AppConfig.getBaseUrl()
                + "download?" + "mediaId=" + head_id + "&type=1";
    }

    /**
     * 是否同一个用户信息
     *
     * @param userInfoA
     * @param userInfoB
     * @return
     */
    public static boolean isSameUserInfo(UserInfo userInfoA, UserInfo userInfoB) {
        if (userInfoA == userInfoB) {
            return true;
        }
        if (userInfoA == null || userInfoB == null) {
            return false;
        }
        return isSameColums(userInfoA.getAge(), userInfoB.getAge())
                && isSameColums(userInfoA.getHead_id(), userInfoB.getHead_id())
                && isSameColums(userInfoA.getNick_name(), userInfoB.getNick_name())
                && isSameColums(userInfoA.getSex(), userInfoB.getSex())
                && isSameColums(userInfoA.getUserId(), userInfoB.getUserId())
                && isSameColums(userInfoA.getType(), userInfoB.getType());
    }


    private static boolean isSameColums(String strA, String strB) {
        return strA == strB || strA != null && strB != null && strA.trim().equalsIgnoreCase(strB.trim());
    }

}
